include ../../rpcsys.mk

TARGET		= libproto_rpcsys.a
SRCS		= $(patsubst %.proto, %.pb.cpp, $(wildcard *.proto))
OBJS     	= $(patsubst %.cpp, %.o, $(SRCS))
TARGET_OBJS	= $(addprefix $(OBJ_DIR)/, $(OBJS))

.PHONY : all clean depend

all : proto depend $(TARGET)

-include .depend

$(TARGET) : $(TARGET_OBJS)
	$(AR) -o $@ $^
	@-(mv $(TARGET) $(RPCSYS_LIBPATH)) 

$(OBJ_DIR)/%.o : %.cpp
	$(CC) $(RPCSYS_CXXFLAG) $(RPCSYS_DEFINED) $(PROTOBUF_INCPATH) -c $< -o $@

depend : $(SRCS)
	$(CC) -MM $(PROTOBUF_INCPATH) $^ > .depend
	@-(./replace.sh)

proto :
	$(PROTOBUF_PROTOC) --proto_path=./ --proto_path=$(PROTOBUF_PROTOPATH) --cpp_out=./ *.proto
	@-(mv rpc_protocol.pb.cc rpc_protocol.pb.cpp)

clean:
	@-(rm $(OBJ_DIR)/*.o $(RPCSYS_LIBPATH)/$(TARGET) .depend *.cpp)
